<?php
Zend::loadClass('Lead_EDO_Datatype_Field');

/**
 * Datatype for smallint
 * 
 * @package EDO
 * @subpackage Datatypes
 *
 */
class Lead_EDO_Datatype_Smallint extends Lead_EDO_Datatype_Field 
{
	protected $_SQLValueIsQuoted = false;
	
	
	function validate($validate)
	{
	    
	    if(!$this->notNull() AND empty($validate) AND !is_numeric($validate))
	    {
	        return null;
	    }
    
		if(!is_numeric($validate))
			return false;
    		
	    if ((string)$validate !== (string)(int)$validate)
	       return false;

		if($validate < -32768 OR $validate > 32768)
			 return false;
		
		return (int) $validate;			
		
		
	}
	
	
	
}